<template>
	<view class="user-container">
		<block v-if="notices.length > 0">
			<view class="cu-list menu" v-for="(notice, idx) in notices" :key="idx" :data-item="notice"
			 @click="gotoDetail(notice)">
				<view class="cu-item arrow">
					<view class="content padding-tb-sm">
						<view>
							<text class="cuIcon-notification text-cut text-green margin-right-xs"></text>
							<view class="text-cut" style="width:220px">{{notice.title}}</view>
						</view>
						<view class="text-gray text-sm">
							<text class="margin-right-xs">发布时间：</text> {{notice.timeStr}}</view>
					</view>
				</view>
			</view>
			<uni-load-more :status="loadingStatus" :content-text="loadingContentText" />
		</block>
		<block v-else>
			<view class="cu-list menu">
				<view class="cu-item">
					<view class="content">
						<text class="cuIcon-notification text-grey"></text>
						<text class="text-grey">暂无公告信息</text>
					</view>
					<view class="action">
					</view>
				</view>
			</view>
		</block>
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import {getAreaId} from '../../api/area/areaApi.js'
	import {queryGovCiviladmin} from '../../api/civiladmin/civiladminApi.js'
	export default {
		data() {
			return {
				caId: getAreaId(),
				communityId: "",
				notices: [],
				currPageIndex: 0,
				pageSize: 10,
				page: 1,
				loadingStatus : 'loading',
				loadingContentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				}
			};
		},
		components: {
			uniLoadMore
		},
		onLoad: function(options) {
			let that = this;
			this.vc.onLoad(options);
			that._loadNotices();
		},
		onShow: function() {
			let that = this;
		},
		onReachBottom : function(){
			if(this.loadingStatus == 'noMore'){
				return;
			}
			this._loadApply();
		},
		methods: {
			_loadNotices: function(){
				this.loadingStatus = 'more';
				let that = this;
				let _paramIn = {
					caId: that.caId,
					page: that.page,
					row: 10,
				};
				queryGovCiviladmin(_paramIn).then(_data =>{
					let _json = _data;
					if (_json.code == 0 && _json.data.length > 0) {
						_json.data.forEach(function(item, index) {
							item.timeStr = item.startTime.replace(/:\d{1,2}$/, ' ');
						});
						that.notices = that.notices.concat(_json.data);
						if(that.notices.length == _json.data.total){
							that.loadingStatus = 'noMore';
							return;
						}
					}else{
						uni.showToast({
							title: "查询失败",
							icon: 'none',
							duration: 2000
						})
					}
				})
			},
			gotoDetail: function(_notice) {
				let that = this;
				this.vc.navigateTo({
					url: "/pages/notice/detail/detail?civiladminId=" + _notice.civiladminId +"&caId="+that.caId
				});
			},
		}
	};
</script>
<style>
	@import "./index.css";
	.cu-list+.cu-list {
	    margin-top: 10px;
	}
</style>
